package com.zzgc.modules.service.impl;

import com.zzgc.common.dao.StudentArchivesDao;
import com.zzgc.common.entity.StudentArchives;
import com.zzgc.modules.param.StudentArchivesParam;
import com.zzgc.modules.service.StudentArchivesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 学生档案模板(StudentArchives)表服务实现类
 *
 * @author makejava
 * @since 2023-01-31 11:18:14
 */
@Service("studentArchivesService")
public class StudentArchivesServiceImpl implements StudentArchivesService {
    @Resource
    private StudentArchivesDao studentArchivesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StudentArchives queryById(Long id, String tableName) {
        return this.studentArchivesDao.queryById(id, tableName);
    }

    /**
     * 通过省级ID， 学年， 筛查次数，查询单条数据
     *
     * @param uniqueId 主键
     * @param year 主键
     * @param number 主键
     * @return 实例对象
     */
    @Override
    public StudentArchives queryByUniqueIdYearNumber(Long uniqueId, String year, Integer number, String tableName) {
        return this.studentArchivesDao.queryByUniqueIdYearNumber(uniqueId, year, number, tableName);
    }

    /**
     * 分页查询
     *
     * @param studentArchives 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public List<StudentArchives> queryByPage(StudentArchives studentArchives) {
        //long total = this.studentArchivesDao.count(studentArchives);
        return this.studentArchivesDao.queryAllByLimit(studentArchives);
    }

    /**
     * 分页查询, 查询学生档案
     *
     * @param archivesParam 筛选条件
     * @return 查询结果
     */
    @Override
    public List<StudentArchivesParam> queryAllByLimitArchives(StudentArchivesParam archivesParam) {
        List<StudentArchivesParam> archivesParams = this.studentArchivesDao.queryAllByLimitArchives(archivesParam);
        long l = this.studentArchivesDao.queryAllByLimitArchivesCount(archivesParam);
        if (l == 0) {
            return new ArrayList<>();
        }
        archivesParams.get(0).setTotal(l);
        return archivesParams;
    }

    /**
     * 分页查询, 查询学生档案, 可以根据县区查询
     *
     * @param archivesParam 筛选条件
     * @return 查询结果
     */
    @Override
    public List<StudentArchivesParam> queryAllByArchives(StudentArchivesParam archivesParam) {
        List<StudentArchivesParam> archivesParams = this.studentArchivesDao.queryAllByArchives(archivesParam);
        long l = this.studentArchivesDao.queryAllByArchivesCount(archivesParam);
        if (l == 0) {
            return new ArrayList<>();
        }
        archivesParams.get(0).setTotal(l);
        return archivesParams;
    }

    @Override
    public Long count(StudentArchives studentArchives) {
        return this.studentArchivesDao.count(studentArchives);
    }

    /**
     * 新增数据
     *
     * @param studentArchives 实例对象
     * @return 实例对象
     */
    @Override
    public StudentArchives insert(StudentArchives studentArchives) {
        this.studentArchivesDao.insert(studentArchives);
        return studentArchives;
    }

    /**
     * 修改数据
     *
     * @param studentArchives 实例对象
     * @return 实例对象
     */
    @Override
    public StudentArchives update(StudentArchives studentArchives) {
        this.studentArchivesDao.update(studentArchives);
        return this.queryById(studentArchives.getId(), studentArchives.getTableName());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.studentArchivesDao.deleteById(id) > 0;
    }
}
